# python2
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab

from __future__ import absolute_import
from __future__ import print_function
#from __future__ import unicode_literals
from __future__ import division
'''
        @author: msune

    Simple example simulating a Server remote method (e.g. rpc)
'''
from pelib.utils import logging

from . import simplexmlparser

'''
    RPC server interface, receives incomming request (in this example an XML request)
    Throws exception containing the messages
'''
logger = logging.get_logger()


def getUserId(metaObj): #Functions always receive the metaObj
    return "lbergesio"

def remoteMethod(credential, request):
    logger.info(request)
    try:
        #"Parse" request
        dicReq = simplexmlparser.parse(request)

        #Invoke policy enforcement
        import mypolicyengine
        returnV = mypolicyengine.verify(dicReq)
    except Exception,e:
        logger.error(str(e))
        returnV=False
    logger.info("VERIFICATION RESULT: %s", str(returnV))

    if returnV:
        logger.info("Doing some fancy stuff...")
        logger.info("Request process ended")
